package com.example.demo.concurrent.scheduleExecutor;

import lombok.extern.slf4j.Slf4j;

import java.sql.Time;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: sfx
 * Date: 2023-03-29
 * Time: 22:48
 */

@Slf4j(topic = "c.TestDemo1")
public class TestDemo1 {
    public static void main(String[] args) {
        ScheduledExecutorService pool = Executors.newScheduledThreadPool(2);
        pool.scheduleWithFixedDelay(()->{
            log.debug("taks1");
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },1,1, TimeUnit.SECONDS);
//        pool.schedule(()->{
//            log.debug("task1");
//            int x = 100/0;
//        },1000, TimeUnit.MILLISECONDS);
//
//        pool.schedule(()->{
//            log.debug("task2");
//        },1000, TimeUnit.MILLISECONDS);
//        log.debug("start");
    }
}